hist(penguins$body_mass_g, xlim =c(2000, 8000), ylim =c(0, 100),main ="Histogram of body mass of penguins")
A base R histogram
hist(penguins$body_mass_g, xlim =c(2000, 8000), ylim =c(0, 100),main ="Histogram of body mass of penguins",xlab ="Body mass [grams]")
A base R histogram
hist(penguins$body_mass_g, xlim =c(2000, 8000), ylim =c(0, 100),main ="Histogram of body mass of penguins",xlab ="Body mass [grams]", ylab ="Count of individuals")
A base R histogram
hist(penguins$body_mass_g, xlim =c(2000, 8000), ylim =c(0, 100),main ="Histogram of body mass of penguins",xlab ="Body mass [grams]", ylab ="Count of individuals",col ="black", border ="white")
A base R histogram
Code
par(mfrow =c(1, 3))species_1 <-filter(penguins, species =="Adelie")hist(species_1$body_mass_g, xlim =c(2000, 8000), ylim =c(0, 100),main ="Species 'Adelie'",xlab ="Body mass [grams]", ylab ="Count of individuals",col ="darkgreen", border ="white")species_2 <-filter(penguins, species =="Chinstrap")hist(species_2$body_mass_g, xlim =c(2000, 8000), ylim =c(0, 100),main ="Species 'Chinstrap'",xlab ="Body mass [grams]", ylab ="Count of individuals",col ="darkblue", border ="white")species_3 <-filter(penguins, species =="Gentoo")hist(species_3$body_mass_g, xlim =c(2000, 8000), ylim =c(0, 100),main ="Species 'Gentoo'",xlab ="Body mass [grams]", ylab ="Count of individuals",col ="darkorange", border ="white")
Base R plots use a single function and specify (a huge) number of optional parameters which change their “aesthetic” properties and visual elements.
Creating a new figure (from the same data even) requires us to write usually a completely different code.
tidyverse provides “grammar for data manipulation”…
ggplot2 provides “grammar for visualizations”…
Layers in “Grammar of Graphics”
Layers in “Grammar of Graphics”
data — our data frame
aesthetics — “mapping” of columns to visual properties of a figure (x, or y axes, color, shape, etc.)
geoms — graphical elements to be plotted (histograms, points, lines, etc.).